﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class AdvertiseDAL : SqlDataProvider
        //hihihi. It's me: hatake kakashi
        //Naruto is me :))
        //SAI is me =))khjkhjkhjjgfhdfjklghdfkjghsdfnghdfgdf,gdfjklgdf
        gdf
            g
            dfg
            d
                gdf
                gg
        //Well Come To Facebook :)
        // cho Duong :))
                    // cho Hoang :))
                   // cho Hoang :))// cho Hoang :))// cho Hoang :))

                    // cho Hoang :))// cho Hoang :))// cho Hoang :))
                    // cho Hoang :))// cho Hoang :))
                    // cho Hoang :))
        //^!^ (.)(.)
        //V0d0i :))
                    //I am champion :))
        //aldfaldia
        //akdjkajdkajdka
        //fkljdojd
    {
        #region[Advertise_GetById]
        public List<Advertise> Advertise_GetById(string Id)
        {
            var list = new List<Advertise>();
            //using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_GetById", GetConnection()))
            //{
            //    //dbCmd.CommandText = "sp_Advertise_GetById";
            //    //dbCmd.Connection = GetConnection();
            //    dbCmd.CommandType = CommandType.StoredProcedure;
            //    dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
            //    SqlDataReader dr = dbCmd.ExecuteReader();
                
            //    if (dr.HasRows)
            //    {
            //        while (dr.Read())
            //        {
            //            list.Add(Advertise.AdvertiseIDataReader(dr));
            //        }
            //    }
            //    dr.Close();
            //}
              
            return list;
        }
        #endregion
        #region[Advertise_GetByTop]
        public List<Advertise> Advertise_GetByTop(string Top, string Where, string Order)
        {
            List<Advertise> list = new List<Advertise>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_GetByTop", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Advertise.AdvertiseIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[Advertise_GetByAll]
        public List<Advertise> Advertise_GetByAll(string Lang)
        {
            List<Advertise> list = new List<Advertise>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_GetByAll", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Advertise.AdvertiseIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[Advertise_Paging]
        public List<Advertise> Advertise_Paging(string CurentPage, string PageSize, string Lang)
        {
            List<Advertise> list = new List<Advertise>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_Paging", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", Lang));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Advertise.AdvertiseIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[Advertise_Insert]
        public bool Advertise_Insert(Advertise data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.Parameters.Add(new SqlParameter("@Width", data.Width));
                dbCmd.Parameters.Add(new SqlParameter("@Height", data.Height));
                dbCmd.Parameters.Add(new SqlParameter("@Link", data.Link));
                dbCmd.Parameters.Add(new SqlParameter("@Target", data.Target));
                dbCmd.Parameters.Add(new SqlParameter("@Content", data.Content));
                dbCmd.Parameters.Add(new SqlParameter("@Position", data.Position));
                dbCmd.Parameters.Add(new SqlParameter("@PageId", data.PageId == "" || data.PageId == "0" ? DBNull.Value : (object)data.PageId));
                dbCmd.Parameters.Add(new SqlParameter("@Click", data.Click));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Advertise");
            return true;
        }
        #endregion
        #region[Advertise_Update]
        public bool Advertise_Update(Advertise data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.Parameters.Add(new SqlParameter("@Width", data.Width));
                dbCmd.Parameters.Add(new SqlParameter("@Height", data.Height));
                dbCmd.Parameters.Add(new SqlParameter("@Link", data.Link));
                dbCmd.Parameters.Add(new SqlParameter("@Target", data.Target));
                dbCmd.Parameters.Add(new SqlParameter("@Content", data.Content));
                dbCmd.Parameters.Add(new SqlParameter("@Position", data.Position));
                dbCmd.Parameters.Add(new SqlParameter("@PageId", data.PageId == "" || data.PageId == "0" ? DBNull.Value : (object)data.PageId));
                dbCmd.Parameters.Add(new SqlParameter("@Click", data.Click));
                dbCmd.Parameters.Add(new SqlParameter("@Ord", data.Ord));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.Parameters.Add(new SqlParameter("@Lang", data.Lang));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Advertise");
            return true;
        }
        #endregion
        #region[Advertise_Delete]
        public bool Advertise_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Advertise_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Advertise");
            return true;
        }
        #endregion
    }
}
